package com.qf.entity;

import com.qf.pojo.CheckNull;
import com.qf.pojo.CheckType;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * sys_user_info
 *
 * @author
 */
public class SysUserInfo implements Serializable, CheckNull {
    /**
     * 用户的主键,自增
     */
    private Integer uId;

    /**
     * 登录用户名,长度在16位内,在使用手机号首次登录时候自动生成,不可更改
     */
    private String username;

    /**
     * 密码需要是散列值,不可以保存明文
     */
    private String password;

    /**
     * 密码散列计算时候的盐值,自动生成,不可主动修改,在使用security后取消使用
     */
    private String pwdSalt;

    /**
     * 用户名字
     */
    private String name;

    /**
     * 注册时候填写或者手机号登录
     */
    private String phone;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 性别,0女,1男
     */
    private Short sex;

    /**
     * 头像地址
     */
    private String avator;

    /**
     * 用户一些其他信息,方便快速查询
     */
    private String info;

    /**
     * 用户类型 1普通,2管理员,3客服,可以自定义扩展,无权限不可以修改
     */
    private Short type;

    /**
     * 用户状态 1正常,2密码错误过多暂停,3暂时封禁,4封禁,5停用,6删除可以扩展,无权限不可以修改
     */
    private Short status;

    /**
     * 本次登录时间,不可以主动修改
     */
    private Date currentLogin;

    /**
     * 用户上次登录时间,不可以主动修改
     */
    private Date lastLogin;

    /**
     * 本次登录ip,不可以主动修改
     */
    private String currentLoginIp;

    /**
     * 上次登录ip,不可以主动修改
     */
    private String lastLoginIp;

    /**
     * 用户创建的时间,不可以主动修改
     */
    private Date createTime;

    /**
     * 谁创建的,普通用户是自己,后台用户是添加用户的管理员,不可以修改
     */
    private String createBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 谁更新的
     */
    private String updateBy;

    /**
     * 用户的标识,如普通用户,就是一个汉字,快速区分type用,无权限不可以修改
     */
    private String remark;

    private static final long serialVersionUID = 1L;


    /**
     * 非空判断
     *
     * @param type
     * @return
     */
    @Override
    public boolean isEmpty(CheckType type) {
        switch (type) {
            case ADD:
                return !StringUtils.hasText(username)
                        || !StringUtils.hasText(password)
                        || !StringUtils.hasText(name)
                        || !StringUtils.hasText(phone)
                        || !StringUtils.hasText(email)
                        || ObjectUtils.isEmpty(sex) || sex < 0;
            default:
                break;
        }
        return CheckNull.super.isEmpty(type);
    }

    public Integer getuId() {
        return uId;
    }

    public void setuId(Integer uId) {
        this.uId = uId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPwdSalt() {
        return pwdSalt;
    }

    public void setPwdSalt(String pwdSalt) {
        this.pwdSalt = pwdSalt;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Short getSex() {
        return sex;
    }

    public void setSex(Short sex) {
        this.sex = sex;
    }

    public String getAvator() {
        return avator;
    }

    public void setAvator(String avator) {
        this.avator = avator;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Short getType() {
        return type;
    }

    public void setType(Short type) {
        this.type = type;
    }

    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public Date getCurrentLogin() {
        return currentLogin;
    }

    public void setCurrentLogin(Date currentLogin) {
        this.currentLogin = currentLogin;
    }

    public Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    public String getCurrentLoginIp() {
        return currentLoginIp;
    }

    public void setCurrentLoginIp(String currentLoginIp) {
        this.currentLoginIp = currentLoginIp;
    }

    public String getLastLoginIp() {
        return lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        SysUserInfo other = (SysUserInfo) that;
        return (this.getuId() == null ? other.getuId() == null : this.getuId().equals(other.getuId()))
                && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
                && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
                && (this.getPwdSalt() == null ? other.getPwdSalt() == null : this.getPwdSalt().equals(other.getPwdSalt()))
                && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
                && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
                && (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
                && (this.getSex() == null ? other.getSex() == null : this.getSex().equals(other.getSex()))
                && (this.getAvator() == null ? other.getAvator() == null : this.getAvator().equals(other.getAvator()))
                && (this.getInfo() == null ? other.getInfo() == null : this.getInfo().equals(other.getInfo()))
                && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
                && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
                && (this.getCurrentLogin() == null ? other.getCurrentLogin() == null : this.getCurrentLogin().equals(other.getCurrentLogin()))
                && (this.getLastLogin() == null ? other.getLastLogin() == null : this.getLastLogin().equals(other.getLastLogin()))
                && (this.getCurrentLoginIp() == null ? other.getCurrentLoginIp() == null : this.getCurrentLoginIp().equals(other.getCurrentLoginIp()))
                && (this.getLastLoginIp() == null ? other.getLastLoginIp() == null : this.getLastLoginIp().equals(other.getLastLoginIp()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getCreateBy() == null ? other.getCreateBy() == null : this.getCreateBy().equals(other.getCreateBy()))
                && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
                && (this.getUpdateBy() == null ? other.getUpdateBy() == null : this.getUpdateBy().equals(other.getUpdateBy()))
                && (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getuId() == null) ? 0 : getuId().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getPwdSalt() == null) ? 0 : getPwdSalt().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
        result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
        result = prime * result + ((getSex() == null) ? 0 : getSex().hashCode());
        result = prime * result + ((getAvator() == null) ? 0 : getAvator().hashCode());
        result = prime * result + ((getInfo() == null) ? 0 : getInfo().hashCode());
        result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        result = prime * result + ((getCurrentLogin() == null) ? 0 : getCurrentLogin().hashCode());
        result = prime * result + ((getLastLogin() == null) ? 0 : getLastLogin().hashCode());
        result = prime * result + ((getCurrentLoginIp() == null) ? 0 : getCurrentLoginIp().hashCode());
        result = prime * result + ((getLastLoginIp() == null) ? 0 : getLastLoginIp().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getCreateBy() == null) ? 0 : getCreateBy().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getUpdateBy() == null) ? 0 : getUpdateBy().hashCode());
        result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", uId=").append(uId);
        sb.append(", username=").append(username);
        sb.append(", password=").append(password);
        sb.append(", pwdSalt=").append(pwdSalt);
        sb.append(", name=").append(name);
        sb.append(", phone=").append(phone);
        sb.append(", email=").append(email);
        sb.append(", sex=").append(sex);
        sb.append(", avator=").append(avator);
        sb.append(", info=").append(info);
        sb.append(", type=").append(type);
        sb.append(", status=").append(status);
        sb.append(", currentLogin=").append(currentLogin);
        sb.append(", lastLogin=").append(lastLogin);
        sb.append(", currentLoginIp=").append(currentLoginIp);
        sb.append(", lastLoginIp=").append(lastLoginIp);
        sb.append(", createTime=").append(createTime);
        sb.append(", createBy=").append(createBy);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", updateBy=").append(updateBy);
        sb.append(", remark=").append(remark);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
